# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=qhull

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgrel=1
pkgver=r113.60d5581
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgdesc="A general dimension code for computing convex hulls and related structures (mingw-w64)"
arch=('any')
url="http://www.${_realname}.org/"
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}")
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("git" 
     "${MINGW_PACKAGE_PREFIX}-gcc" 
     "${MINGW_PACKAGE_PREFIX}-cmake")
source=("$_realname"::"git://gitorious.org/qhull/qhull.git"
    mingw-cmake.patch)
sha1sums=('SKIP'
          '6a574af41f6b1b8bacf3fab144c52b0a2bfb4fa4')

pkgver() {
  cd "$srcdir/$_realname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd $srcdir/$_realname
  patch -p1 -i $srcdir/mingw-cmake.patch
}

build() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
    export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  pushd ${MINGW_PREFIX} > /dev/null
    export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${PREFIX_WIN} \
    -DBUILD_SHARED_LIBS=ON \
    $srcdir/$_realname
  make
}

package() {
  cd "$srcdir/build-${CARCH}"
  make install # DESTDIR="$pkgdir"
  pushd ${pkgdir}${MINGW_PREFIX}/lib >/dev/null
  if [ -f lib${_realname}static.a ]; then
    mv -f lib${_realname}static.a lib${_realname}.a
  fi
  if [ -f lib${_realname}static_p.a ]; then
    mv -f lib${_realname}static_p.a lib${_realname}_p.a
  fi
  popd >/dev/null
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname  
  cp -pf ${srcdir}/${_realname}/COPYING* \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname
}
